package com.hoopchina.util.json;

import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
 * SearchRemindJsonInfo 获得搜索建议 json 
 * 
 * @author Guo Baiyu
 */
public class SearchRemindJsonInfo extends JsonInfo {
    
 
    /**
     * 
     */
    public SearchRemindJsonInfo() {
        super();

    }
    
    
    /**
     * @param mUrl
     */
    public SearchRemindJsonInfo( String url ) {
        super(url);
    }
    


    /**
     * 解析json
     */
    @Override
    public List<String> parseJson( String jsonData ) {
        List<String> list = new ArrayList<String>();
        
        try {
            int startIndex = jsonData.indexOf( "(" );
			int endIndex = 0;
            if (startIndex != -1) {
				endIndex	= jsonData.indexOf( ");" );
			}
			if (endIndex == 0 || endIndex == -1) {
				return list;
			}
            String js = jsonData.substring( startIndex + 1, endIndex );
            
            if(null == js || js.trim().equals("")){
                return list;
            }
            //
            JSONObject root = new JSONObject( js );
            String rsp = root.getString( "q" );
            list.add( rsp );
            JSONArray items = root.optJSONArray( "s" );
            for ( int i = 0; i < items.length(); i++ ) {
                list.add( items.getString( i ) );
            }
        }
        catch (StringIndexOutOfBoundsException e) {
            e.printStackTrace();
        }
        catch ( JSONException e ) {
            e.printStackTrace();
        }
        return list;
    }
}
